import { defineStore } from "pinia";
import { ref } from "vue";

export const useAuthStore = defineStore('auth', () => {
    const user = ref({})
    const isAuthenticated = ref(false)

    function loginSuccess(userData) {
        user.value = userData
        isAuthenticated.value = true
        localStorage.setItem('user', JSON.stringify(userData));
    }

    function logout() {
        user.value = null
        isAuthenticated.value = false
        localStorage.removeItem('user')
    }

    return { user, isAuthenticated, loginSuccess, logout }
})